package com.sias;

import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import java.util.Map;

/**
 * @author 吴文杰
 * @version 1.0
 * @since $DATE $TIME
 */
public class Main {
  public static void main(String[] args) throws Exception {
    AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext(WebConfig.class);

    RequestMappingHandlerMapping handlerMapping = context.getBean(RequestMappingHandlerMapping.class);

    Map<RequestMappingInfo, HandlerMethod> handlerMethods = handlerMapping.getHandlerMethods();
    handlerMethods.forEach((k,v)->{
      System.out.println("key ="+k+"value =" +v);
    });

    HandlerExecutionChain chain = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/test"));
    System.out.println(chain);

    MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/test2");
    request.addHeader("token","lingpai");
    HandlerExecutionChain handler = handlerMapping.getHandler(request);
    MockHttpServletResponse response = new MockHttpServletResponse();
    System.out.println(handler);


    RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);

  }
}